package cn.yuanqiao.es.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

/**
 * @ProjectName: ruoyi-modules-system
 * @Package: cn.yuanqiao.es.enums
 * @ClassName: EsClientConfig
 * @Author: lenovo
 * @Description: hbWang
 * @Date: 2023/6/30 16:04
 * @Version: 1.0
 */
@Configuration
public class EsClientConfig {
    @Value(value = "${spring.elasticsearch.rest.uris}")
    private String uris;

    @Value("${spring.elasticsearch.rest.username}")
    private String username;

    @Value("${spring.elasticsearch.rest.password}")
    private String password;


    private static String urisStatic;
    private static String usernameStatic;
    private static String passwordStatic;

    //SCROLL查询 2小时
    public static final long DEFAULT_SCROLL_TIME = 2;
    //SCROLL查询 每页默认条数
    public static final int DEFAULT_SCROLL_PERPAGE = 100;
    //非分页，默认的查询条数
    public static final int DEFALT_PAGE_SIZE = 200;
    // 批量更新（新增）每批次条数
    public static final int BULK_COUNT = 5 * 1000;

    // 从连接池获取连接的超时时间，0代表一直等待
    public static final int ES_CONNECTION_REQ_TIMEOUT = 0;
    // 与服务器建立连接的超时时间
    public static final int ES_CONNECTION_TIMEOUT = 60 * 1000;
    // 网络通讯的超时时间
    public static final int ES_SOCKET_TIMEOUT = 60 * 1000;

    //搜索建议默认条数
    public static final int COMPLETION_SUGGESTION_SIZE = 10;

    @PostConstruct
    public void init() {
        urisStatic = uris;
        usernameStatic = username;
        passwordStatic = password;
    }

    public static String getUrisStatic() {
        return urisStatic;
    }

    public static String getUsernameStatic() {
        return usernameStatic;
    }

    public static String getPasswordStatic() {
        return passwordStatic;
    }
}
